<template>
    <view class="store-page">
        <!-- 顶部导航栏 -->
        <view class="header">
            <view class="back" @tap="goBack">
                <text class="iconfont icon-left"></text>
            </view>
            <view class="title">选择门店</view>
        </view>

        <!-- 搜索区域 -->
        <view class="search-box">
            <view class="location">
                <text class="iconfont icon-location"></text>
                <text>广州</text>
            </view>
            <view class="search-input" @tap="goToSearch">
                <text class="iconfont icon-search"></text>
                <input type="text" placeholder="请输入关键词搜索" disabled />
            </view>
        </view>

        <!-- 门店列表 -->
        <view class="store-list">
            <view class="section-title">附近</view>

            <view class="store-item" v-for="(item, index) in storeList" :key="index" @tap="selectStore(item)">
                <view class="store-name">{{ item.name }}</view>
                <view class="store-address">{{ item.address }}</view>
                <view class="store-info">
                    <text class="business-hours">营业时间: {{ item.businessHours }}</text>
                    <text class="distance">{{ item.distance }}公里</text>
                </view>
            </view>

            <view class="load-more" @tap="loadMore" v-if="!showAll">查看更多</view>
        </view>

        <!-- 添加门店选择弹窗 -->
        <view class="store-popup" v-if="showPopup" @tap.stop="closePopup">
            <view class="popup-content" @tap.stop>
                <view class="close-btn" @tap="closePopup">
                    <!-- <text class="iconfont icon-close"></text> -->
                </view>
                <view class="popup-store-name">{{ selectedStore.name }}</view>
                <view class="popup-store-address">{{ selectedStore.address }}</view>
                <view class="popup-order-type">
                    <view class="order-type-item active">
                        <view class="icon-wrap">
                            <!-- <text class="iconfont icon-diancan"></text> -->
                            <view>✔</view>
                        </view>
                        <text>现在点餐</text>
                        <text class="desc">支付成功后取餐</text>
                    </view>
                </view>
                <view class="start-btn" @tap="startOrder">开始</view>
            </view>
        </view>

        <!-- 添加提示弹窗 -->
        <view class="tip-popup" v-if="showTipPopup">
            <view class="tip-content">
                <view class="tip-text">
                    点餐为第三方供应商提供的代下单服务。当你支付后，请凭取餐码等候门店屏幕的显示即可取餐。如有疑问请联系我们客服。
                </view>
                <view class="tip-btns">
                    <view class="btn cancel" @tap="closeTipPopup">取消</view>
                    <view class="btn confirm" @tap="confirmOrder">继续下单</view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            keyword: '',
            pageSize: 3, // 每页显示数量
            showAll: false, // 是否显示全部
            allStores: [
                {
                    name: '广东广州东方宝泰永旺店',
                    address: '广东省广州市天河区林和中路63号B2部分自编TB189',
                    businessHours: '10:00 - 22:00',
                    distance: '1.0'
                },
                {
                    name: '广东广州天河中信广场店',
                    address: '广东省广州市天河区天河北路233号中信广场商场128-129单元',
                    businessHours: '08:00 - 21:00',
                    distance: '1.3'
                },
                {
                    name: '广东广州保利中辰广场店',
                    address: '广东省广州市天河区龙口西路3号保利中辰广场103房商铺',
                    businessHours: '09:00 - 23:59',
                    distance: '1.8'
                },
                {
                    name: '广东广州正佳广场店',
                    address: '广东省广州市天河区天河路228号正佳广场4楼',
                    businessHours: '10:00 - 22:00',
                    distance: '2.1'
                },
                {
                    name: '广东广州天环广场店',
                    address: '广东省广州市天河区天河路218号天环广场负一层',
                    businessHours: '10:00 - 22:00',
                    distance: '2.3'
                }
            ],
            showPopup: false,
            selectedStore: null,
            showTipPopup: false
        }
    },
    computed: {
        storeList() {
            if (this.showAll) {
                return this.allStores;
            }
            return this.allStores.slice(0, this.pageSize);
        }
    },
    methods: {
        goBack() {
            uni.navigateBack()
        },
        selectStore(store) {
            this.selectedStore = store;
            this.showPopup = true;
        },
        closePopup() {
            this.showPopup = false;
            this.selectedStore = null;
        },
        startOrder() {
            this.showTipPopup = true;
        },
        closeTipPopup() {
            this.showTipPopup = false;
        },
        confirmOrder() {
            // 关闭提示弹窗
            this.showTipPopup = false;
            // 跳转到商品列表页
            uni.navigateTo({
                url: '/pagesZone/drink/menu'
            });
        },
        loadMore() {
            this.showAll = true;
        },
        goToSearch() {
            uni.navigateTo({
                url: '/pagesZone/drink/search'
            });
        }
    }
}
</script>

<style lang="scss" scoped>
.store-page {
    min-height: 100vh;
    background-color: #f5f5f5;
}

.header {
    display: flex;
    align-items: center;
    height: 88rpx;
    padding: 0 30rpx;
    background-color: #fff;
    position: relative;

    .back {
        position: absolute;
        left: 30rpx;
        font-size: 40rpx;
    }

    .title {
        flex: 1;
        text-align: center;
        font-size: 34rpx;
        font-weight: 500;
    }
}

.search-box {
    display: flex;
    align-items: center;
    padding: 20rpx 30rpx;
    background-color: #fff;

    .location {
        display: flex;
        align-items: center;
        margin-right: 20rpx;

        .icon-location {
            color: #ff8f1f;
            margin-right: 6rpx;
        }
    }

    .search-input {
        flex: 1;
        display: flex;
        align-items: center;
        height: 72rpx;
        background-color: #f5f5f5;
        border-radius: 36rpx;
        padding: 0 30rpx;

        position: relative;
        cursor: pointer;

        input {
            flex: 1;
            font-size: 28rpx;
            background-color: transparent;
            pointer-events: none;
        }

        &:active {
            opacity: 0.8;
        }
    }
}

.store-list {
    padding: 20rpx 30rpx;

    .section-title {
        font-size: 28rpx;
        color: #666;
        margin-bottom: 20rpx;
    }

    .store-item {
        background-color: #fff;
        border-radius: 12rpx;
        padding: 30rpx;
        margin-bottom: 20rpx;

        .store-name {
            font-size: 32rpx;
            font-weight: 500;
            margin-bottom: 12rpx;
        }

        .store-address {
            font-size: 28rpx;
            color: #666;
            margin-bottom: 12rpx;
        }

        .store-info {
            display: flex;
            justify-content: space-between;
            font-size: 26rpx;
            color: #999;

            .distance {
                color: #666;
            }
        }
    }

    .load-more {
        text-align: center;
        color: #666;
        font-size: 28rpx;
        padding: 20rpx 0;

        &:active {
            opacity: 0.7;
        }
    }
}

.store-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 999;
    display: flex;
    align-items: flex-end;

    .popup-content {
        width: 100%;
        background-color: #fff;
        border-radius: 24rpx 24rpx 0 0;
        padding: 40rpx 30rpx;
        position: relative;

        .close-btn {
            position: absolute;
            right: 30rpx;
            top: 30rpx;
            padding: 10rpx;

            .icon-close {
                font-size: 40rpx;
                color: #999;
            }
        }

        .popup-store-name {
            font-size: 36rpx;
            font-weight: bold;
            margin-bottom: 16rpx;
            padding-right: 60rpx;
        }

        .popup-store-address {
            font-size: 28rpx;
            color: #666;
            margin-bottom: 40rpx;
        }

        .popup-order-type {
            .order-type-item {
                display: flex;
                align-items: center;
                padding: 30rpx;
                background-color: #f8f8f8;
                border-radius: 12rpx;
                margin-bottom: 20rpx;

                &.active {
                    background-color: #FFF7F7;
                    border: 2rpx solid #FF0000;
                }

                .icon-wrap {
                    width: 60rpx;
                    height: 60rpx;
                    background-color: #FF0000;
                    border-radius: 50%;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    margin-right: 20rpx;
                    color: #fff;

                    .icon-diancan {
                        color: #fff;
                        font-size: 40rpx;
                    }
                }

                text {
                    font-size: 32rpx;
                    font-weight: 500;
                }

                .desc {
                    font-size: 24rpx;
                    color: #999;
                    margin-left: auto;
                }
            }
        }

        .start-btn {
            height: 88rpx;
            background-color: #FF0000;
            color: #fff;
            font-size: 32rpx;
            font-weight: 500;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 44rpx;
            margin-top: 40rpx;

            &:active {
                opacity: 0.9;
            }
        }
    }
}

.tip-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 60rpx;

    .tip-content {
        width: 100%;
        background-color: #fff;
        border-radius: 24rpx;
        padding: 40rpx 30rpx;

        .tip-text {
            font-size: 28rpx;
            color: #333;
            line-height: 1.6;
            text-align: center;
            margin-bottom: 40rpx;
        }

        .tip-btns {
            display: flex;
            border-top: 1rpx solid #eee;
            padding-top: 30rpx;

            .btn {
                flex: 1;
                height: 80rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 32rpx;

                &.cancel {
                    color: #333;
                }

                &.confirm {
                    color: #FF0000;
                    border-left: 1rpx solid #eee;
                }

                &:active {
                    opacity: 0.7;
                }
            }
        }
    }
}
</style>
